const webpackMerger = require('webpack-merge');
const baseConfig = require('./webpack.base');
const { srcDir, distDir } = require('./path');
const theme = require('./theme');

const devConfig = {
  mode: 'development',

  devtool: 'cheap-module-eval-source-map',

  output: {
    filename: '[name].js',
    chunkFilename: '[name].js',
  },

  watchOptions: {
    ignored: /node_modules/, // 不监听node_modules的变化
  },

  devServer: {
    contentBase: distDir,
    port: 8080,
    open: true,
    hot: true,
    stats: 'minimal', // 减少冗余输出
    historyApiFallback: true,
    overlay: { // 在浏览器中显示警报和错误
      warnings: true,
      errors: true,
    },
  },

  module: {
    rules: [
      {
        test: /\.css$/,
        exclude: /node_modules/,
        include: srcDir,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: { importLoaders: 1 },
          },
          'postcss-loader',
        ],
      },
      {
        test: /\.scss$/,
        exclude: /node_modules/,
        include: srcDir,
        use: [
          'style-loader',
          {
            loader: 'css-loader',
            options: { importLoaders: 2 },
          },
          'postcss-loader',
          'sass-loader',
        ],
      },
      {
        test: /\.less$/,
        include: /node_modules\/antd/,
        use: [
          'style-loader',
          'css-loader',
          'postcss-loader',
          {
            loader: 'less-loader',
            options: { modifyVars: theme, javascriptEnabled: true },
          },
        ],
      },
    ],
  },
};

module.exports = webpackMerger(baseConfig, devConfig);
